﻿using System;
using System.Collections.Generic;

namespace Battle.Engine
{
    public static class Mathf
    {
        public const double PI = 3.14159274f;
        public const double Infinity = double.PositiveInfinity;
        public const double NegativeInfinity = double.NegativeInfinity;
        public const double Deg2Rad = 0.0174532924f;
        public const double Rad2Deg = 57.29578f;
        public const double Epsilon = double.Epsilon;
        public static double Sin(double f)
        {
            return (double)Math.Sin((double)f);
        }

        public static double Cos(double f)
        {
            return (double)Math.Cos((double)f);
        }
        public static double Abs(double value)
        {
            return Math.Abs(value);
        }
        public static int Abs(int value)
        {
            return Math.Abs(value);
        }
        public static double Pow(double f, double p)
        {
            return (double)Math.Pow((double)f, (double)p);
        }
        public static bool Approximately(double a, double b)
        {
            return (Abs((double)(b - a)) < Max((double)(1E-06f * Max(Abs(a), Abs(b))), (double)1.121039E-44f));
        }
        public static double Lerp(double from, double to, double t)
        {
            return (from + ((to - from) * Clamp01(t)));
        }

        public static double Clamp01(double value)
        {
            if (value < 0f)
            {
                return 0f;
            }
            if (value > 1f)
            {
                return 1f;
            }
            return value;
        }

        public static int Clamp(int value, int min, int max)
        {
            if (value < min)
            {
                value = min;
                return value;
            }
            if (value > max)
            {
                value = max;
            }
            return value;
        }
        public static double Clamp(double value, double min, double max)
        {
            if (value < min)
            {
                value = min;
                return value;
            }
            if (value > max)
            {
                value = max;
            }
            return value;
        }


        public static int CeilToInt(double f)
        {
            return (int)Math.Ceiling((double)f);
        }

        public static int FloorToInt(double f)
        {
            return (int)Math.Floor((double)f);
        }

        public static int RoundToInt(double f)
        {
            return (int)Math.Round((double)f);
        }

        public static double Ceil(double f)
        {
            return (double)Math.Ceiling((double)f);
        }

        public static double Floor(double f)
        {
            return (double)Math.Floor((double)f);
        }

        public static double Round(double f)
        {
            return (double)Math.Round((double)f);
        }
        public static int Max(int a, int b)
        {
            return ((a <= b) ? b : a);
        }

        public static int Max(params int[] values)
        {
            int length = values.Length;
            if (length == 0)
            {
                return 0;
            }
            int num2 = values[0];
            for (int i = 1; i < length; i++)
            {
                if (values[i] > num2)
                {
                    num2 = values[i];
                }
            }
            return num2;
        }

        public static double Max(params double[] values)
        {
            int length = values.Length;
            if (length == 0)
            {
                return 0f;
            }
            double num2 = values[0];
            for (int i = 1; i < length; i++)
            {
                if (values[i] > num2)
                {
                    num2 = values[i];
                }
            }
            return num2;
        }
        public static double Min(double a, double b)
        {
            return ((a >= b) ? b : a);
        }

        public static double Min(params double[] values)
        {
            int length = values.Length;
            if (length == 0)
            {
                return 0f;
            }
            double num2 = values[0];
            for (int i = 1; i < length; i++)
            {
                if (values[i] < num2)
                {
                    num2 = values[i];
                }
            }
            return num2;
        }

        public static int Min(int a, int b)
        {
            return ((a >= b) ? b : a);
        }

        public static int Min(params int[] values)
        {
            int length = values.Length;
            if (length == 0)
            {
                return 0;
            }
            int num2 = values[0];
            for (int i = 1; i < length; i++)
            {
                if (values[i] < num2)
                {
                    num2 = values[i];
                }
            }
            return num2;
        }
        public static double Acos(double f)
        {
            return (double)Math.Acos((double)f);
        }

        public static double Asin(double f)
        {
            return (double)Math.Asin((double)f);
        }

        public static double Atan(double f)
        {
            return (double)Math.Atan((double)(f));
        }
        public static double Max(double a, double b)
        {
            return ((a <= b) ? b : a);
        }
        public static double Sqrt(double f)
        {
            return (double)Math.Sqrt((double)f);
        }
    }
}

